VERSION 5.00
Begin VB.Form frmResponse 
   Caption         =   "Response"
   ClientHeight    =   2010
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   4680
   LinkTopic       =   "Form1"
   ScaleHeight     =   2010
   ScaleWidth      =   4680
   StartUpPosition =   3  'Windows Default
   Begin VB.CommandButton cmdEnter 
      Caption         =   "Enter"
      Height          =   855
      Left            =   1200
      TabIndex        =   0
      Top             =   480
      Width           =   2295
   End
End
Attribute VB_Name = "frmResponse"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Private Sub cmdEnter_Click()

Dim adoConn As ADODB.Connection
Dim adoRSResponse As ADODB.Recordset
Dim adoComm As ADODB.Command
Dim blApproveResponse As Boolean
Dim blDeclineResponse As Boolean
Dim blCancelResponse As Boolean
Dim nNumResRecords As String
Dim nReqSeqNum As String
Dim nReqStatus As String
Dim sErrorMessage As String
Dim strFailReason As String

On Error GoTo PROC_ERROR

Set adoConn = New ADODB.Connection
With adoConn
    .CursorLocation = adUseClient
    .ConnectionString = GetConnectionString() 'Johann (20090625): Centralised code for connection string added
    .Open
End With

Set adoRSResponse = New ADODB.Recordset
With adoRSResponse
    .CursorLocation = adUseClient
    .CursorType = adOpenStatic
End With

Set adoComm = New ADODB.Command
With adoComm
    .CommandText = "Select * from dir_response where req_seq_num in (Select req_seq_num from dir_interface_index where SARS_Response_YN = 'N')"
    .CommandType = adCmdText
    Set .ActiveConnection = adoConn
End With
    
Set adoRSResponse = adoComm.Execute
nNumResRecords = adoRSResponse.RecordCount

'Validate recordset exists
Dim blRecordsetEmpty As Boolean
Dim dllRecordsetExist As clsIsEmpty
Set dllRecordsetExist = New clsIsEmpty

blRecordsetEmpty = dllRecordsetExist.IsEmpty(adoRSResponse)

If blRecordsetEmpty = True Then
'If nNumResRecords < 1 Then
        strFailReason = "There was no Response data to extract"
        MsgBox strFailReason, vbOKOnly, Error
        nNumResRecords = 0
        Exit Sub
Else
    Do While adoRSResponse.EOF = False
    nReqSeqNum = adoRSResponse.Fields("req_seq_num").Value
    nReqStatus = adoRSResponse.Fields("request_status").Value

    Select Case nReqStatus
            'Response - request approved / finilised
            Case "07"
                Dim dllApproveResponse As Object
                Set dllApproveResponse = CreateObject("Directive_Response.clsGetDirResData")
                blApproveResponse = dllApproveResponse.GetDirectiveRespData(nReqSeqNum, strFailReason)
                If blApproveResponse = False Then
                    MsgBox strFailReason, 48
                    Exit Sub
                End If
            'Call Decline_Response.dll
            Case "01"
                Dim dllDeclineResponse01 As Object
                Set dllDeclineResponse01 = CreateObject("Decline_Response.clsGetDeclineReasons")
                blDeclineResponse = dllDeclineResponse01.GetDeclineReasons(nReqSeqNum, strFailReason)
                If blDeclineResponse = False Then
                    MsgBox strFailReason, 48
                    Exit Sub
                End If
            'Call Decline_Response.dll
            Case "02"
                Dim dllDeclineResponse02 As Object
                Set dllDeclineResponse02 = CreateObject("Decline_Response.clsGetDeclineReasons")
                blDeclineResponse = dllDeclineResponse02.GetDeclineReasons(nReqSeqNum, strFailReason)
                If blDeclineResponse = False Then
                    MsgBox strFailReason, 48
                    Exit Sub
                End If
            'Call Cancel_response.dll
            Case "08"
                Dim dllCancelResponse As Object
                Set dllCancelResponse = CreateObject("Cancel_Response.clsGetCancelDirData")
                blCancelResponse = dllCancelResponse.GetCancelDirective(nReqSeqNum, strFailReason)
                If blCancelResponse = False Then
                    MsgBox strFailReason, 48
                    Exit Sub
                End If
            
    End Select
    
    'Update index table - set SARS_Response_YN = Y
    Dim adoCommUpdateIndex As ADODB.Command
    Set adoCommUpdateIndex = New ADODB.Command
    With adoCommUpdateIndex
        .CommandText = "Update dir_interface_index set sars_response_yn = 'Y' where req_seq_num = " & nReqSeqNum
        .CommandType = adCmdText
        Set .ActiveConnection = adoConn
    End With
    
    adoCommUpdateIndex.Execute
    
    adoRSResponse.MoveNext
    
    
    Loop
    
End If

'clean up
adoRSResponse.Close
Set adoRSResponse = Nothing
adoConn.Close
Set adoConn = Nothing
Set adoComm = Nothing
Set dllApproveResponse = Nothing
Set dllDeclineResponse01 = Nothing
Set dllDeclineResponse02 = Nothing
Set dllCancelResponse = Nothing
Set adoCommUpdateIndex = Nothing



    
PROC_EXIT:
  Exit Sub

PROC_ERROR:
  Err.Raise Err.Number, _
            "frmResponse", _
            Err.Description
            
Resume PROC_EXIT

End Sub
